using IQIGame.Onigao.Logic;
using System.Collections.Generic;
using UnityEngine;

namespace IQIGame.Onigao.GamePlay
{
    public partial class LevelPlayBaseEntity : IConditionPropFetcher //因为视图层实体暂时不支持DynCfgKey，所以无需实现IConditionDynCfgKeyPropFetcher
    {
        public int FetchConditionProp(ConditionBlackboard blackboard, int iType, IReadOnlyList<int> curValueParams)
        {
            ConditionEntityPropType type = (ConditionEntityPropType)iType;
            DynLevelEntity dynEntity = GetDynLevelEntity();
            switch (type)
            {
                case ConditionEntityPropType.IsHeroInSight:
                    return 0;
                case ConditionEntityPropType.IsStoppedElevator:
                    return 0;
                case ConditionEntityPropType.DistanceToOther:
                    return 0;
                case ConditionEntityPropType.ExecCounts:
                    return dynEntity.execCount;
                case ConditionEntityPropType.IsObstacleActive:
                    return dynEntity.isObstacleActive ? 1 : 0;
                case ConditionEntityPropType.ElevatorCurFloor:
                    LevelElevatorComponent elevatorComponent = this.GetLevelElevatorComponent();
                    return elevatorComponent.floor;
                case ConditionEntityPropType.HaveBuff:
                    int buffCid = curValueParams[1];
                    return dynEntity.buffHolder.ContainsBuff(buffCid) ? 1 : 0;
                case ConditionEntityPropType.DistanceToPosition:
                    int x = curValueParams[1];
                    int y = curValueParams[2];
                    int z = curValueParams[3];
                    Vector3 targetPos = GameMathUtil.LogicPos2UnityPos(x, y, z);
                    Vector3 entityPos = new Vector3(dynEntity.x, dynEntity.y, dynEntity.z);
                    return (int)((targetPos - entityPos).sqrMagnitude * GameGlobalConst.LogicPosScale);
                default:
                    LogicLog.LogError($"关卡视图层不支持的条件类型：3 - {iType}");
                    return 0;
            }
        }
    }
}
